package com.yangguang.huahui.mvp.presenter;

import com.yangguang.huahui.entity.HttpResult;
import com.yangguang.huahui.entity.Login;
import com.yangguang.huahui.mvp.model.LoginModel;
import com.yangguang.huahui.mvp.view.RegisterView;
import com.yangguang.huahui.rx.RxManager;
import com.yangguang.huahui.rx.RxSubscriber;

import java.io.IOException;

import okhttp3.ResponseBody;

/**
 * Created by Administrator on 2017/3/1.
 */

public class RegisterPresenter extends BasePresenter<RegisterView>{
    LoginModel loginModel;

    public RegisterPresenter() {
        loginModel = new LoginModel();
    }

    public void getCode(String phone){
        mSubscription = RxManager.getInstance().doSubscribe(loginModel.getCode(phone), new RxSubscriber<HttpResult>(false) {
            @Override
            protected void _onNext(HttpResult httpResult) {
                mView.onCode(httpResult);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }

    public void register(String phone, String code, String password, String imei, String phone_model,
                         String phone_system, String phone_version, double lat, double lng){
        mSubscription = RxManager.getInstance().doSubscribe(loginModel.register(phone, code, password, imei, phone_model, phone_system, phone_version, lat, lng), new RxSubscriber<Login>(false) {
            @Override
            protected void _onNext(Login login) {
                mView.onRegister(login);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
}
